package com.apes.hr.cultivate.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.hr.cultivate.model.CultivatePlan;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * @author Linwz
 * @create 2019-06-17 15:11
 */
public interface CultivatePlanRepository extends CustomRepository<CultivatePlan, String>{
    @Query("select T from CultivatePlan T where 1 = 1 and (id like %:value% or name like %:value%) ")
    Page<CultivatePlan> find(@Param("value") String value, Pageable pageable);


    @Query(value = "select T.* from hr_cultivate_plan T where 1 = 1 and  name=:value and state != 'delete' ",nativeQuery = true)
    CultivatePlan find(@Param("value") String value);

    @Query("select T from CultivatePlan T where 1 = 1 and state ='approve' and beginDate >=sysdate  and endDate<=sysdate and (id like %:value% or name like %:value%)  ")
    Page<CultivatePlan> findByStateAndBeginDateAndEndDate(@Param("value") String value,  Pageable pageable);


    @Query("select T from CultivatePlan T where 1 = 1 and state ='approve' and (id like %:value% or name like %:value%)  ")
    Page<CultivatePlan> findByState(@Param("value") String value,  Pageable pageable);
}
